home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / qrt.lzh / QRT.H < prev    next >
C/C++ Source or Header  |  1989-02-17  |  10KB  |  354 lines

  1. /**********************************************************
  2.  
  3.  
  4.              Header file for Quick Ray Trace
  5.  
  6.                      Steve Koren
  7.  
  8.  **********************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <math.h>
  12.  
  13. #define TRUE  1
  14. #define FALSE 0
  15.  
  16. #define BOOL short
  17.  
  18. /**********************************************************
  19.  
  20.                      MACHINE TYPES
  21.  
  22.  **********************************************************/
  23.  
  24. #undef  AMIGA
  25. #define UNIX
  26.  
  27. /**********************************************************
  28.  
  29.                  MACHINE SPECIFIC STUFF
  30.  
  31.  **********************************************************/
  32.  
  33. # ifdef UNIX
  34. #   define PI  3.141592
  35. #   define PI2 1.570796
  36. # endif
  37.  
  38. /**********************************************************
  39.  
  40.                      OBJECT  NUMBERS
  41.  
  42.  **********************************************************/
  43.  
  44. #define LINE               1
  45. #define SPHERE             2
  46. #define PARALLELOGRAM      3
  47. #define TRIANGLE           4
  48. #define LAMP               5
  49. #define OBSERVER           6
  50. #define GROUND             7
  51. #define SKY                8
  52. #define BBOX               9
  53. #define RING               10
  54. #define QUADRATIC          11
  55.  
  56.  
  57. /**********************************************************
  58.  
  59.                    PROGRAM CONSTANTS
  60.  
  61.  **********************************************************/
  62.  
  63. #define SMALL              1.0E-3
  64.  
  65. #define ASPECT  0.56       /* aspect ratio */
  66. #define CENTERX 320        /* center of screen */
  67. #define CENTERY 200
  68. #define XSIZE   640        /* x and y size */
  69. #define YSIZE   400
  70. #define CNUM    100        /* this many shades/color */
  71. #define SLEN    64         /* max string length */
  72. #define XSIZE4  160        /* xsize /4 */
  73. #define MAX_IX  4          /* maximum x interpolation */
  74. #define MAX_IY  4          /* maximum y interpolation */
  75.  
  76.  
  77. /**********************************************************
  78.  
  79.                       VECTOR STRUCTURES
  80.  
  81.  **********************************************************/
  82.  
  83. typedef struct vector {        /* a vector in 3 space */
  84.   float x,y,z;
  85. } VECTOR, *VECT_PTR;
  86.  
  87. typedef struct svector {       /* an r,g,b color vector */
  88.   short r,g,b;
  89. } SVECTOR, *SVECT_PTR;
  90.  
  91. typedef struct cinfo_struct {  /* color information */
  92.  
  93.   SVECTOR       amb,           /* ambient lighting */
  94.                 diff,          /* diffuse lighting */
  95.                 mirror,        /* % light reflected */
  96.                 trans;         /* % light transmitted */
  97.  
  98.   VECTOR        density;       /* density */
  99.  
  100.   float         sreflect,      /* specular refl coefficient */
  101.                 index;         /* index if refraction */
  102.  
  103.   short         fuzz,          /* currently unused */
  104.                 reflect,       /* percent specularly reflected */
  105.                 dither;        /* color dithering. 3..6 look ok */
  106.  
  107. } CINFO, *CINFO_PTR;
  108.  
  109.  
  110. /**********************************************************
  111.  
  112.                 PRECOMPUTED INFO FOR OBJECTS
  113.  
  114.  These fields can be used by object routines however
  115.  they wish.  They just make object/line intersections
  116.  faster.
  117.  
  118.  **********************************************************/
  119.  
  120. typedef struct _pre {
  121.  
  122.   float    sin1, cos1,         /* sin and cos */
  123.            sin2, cos2,
  124.            n1,                 /* misc number */
  125.            len1, len2;         /* lengths of vectors */
  126.  
  127.   VECTOR   vect1,              /* misc vector */
  128.            norm;               /* norm for planar objs */
  129.  
  130. } PRECOMP, PRECOMP_PTR;
  131.  
  132.  
  133. /**********************************************************
  134.  
  135.                       PATTERN STRUCTURE
  136.  
  137.  **********************************************************/
  138.  
  139. typedef struct patt {
  140.   short    type;               /* type of pattern */
  141.   float    xsize,              /* pattern size */
  142.            ysize,
  143.            startx,
  144.            starty,             /* x,y positions */
  145.            endx,
  146.            endy,
  147.            radius;             /* rad for circles */
  148.  
  149.   CINFO    cinfo;              /* color information */
  150.  
  151.   char     *name;              /* pattern name */
  152.  
  153.   struct patt *child, *sibling, *link;
  154.  
  155. } PATTERN, *PATTERN_PTR;
  156.  
  157.  
  158. /**********************************************************
  159.  
  160.                     OBJECT STRUCTURE
  161.  
  162.  **********************************************************/
  163.  
  164. typedef struct obj_struct {
  165.  
  166.   short         type,         /* object type */
  167.                 flag;         /* misc boolean flag */
  168.  
  169.   char          *name;        /* object name */
  170.  
  171.   VECTOR        loc,          /* object location */
  172.                 vect1,        /* three vectors */
  173.                 vect2,
  174.                 vect3,
  175.                 lower,        /* lower and upper bounds */
  176.                 upper;
  177.  
  178.   float         cterm,        /* for quadratic surfaces only */
  179.                 xmult,        /* x and y multipliers for patterns */
  180.                 ymult;
  181.  
  182.   CINFO         cinfo;        /* color information */
  183.  
  184.   PRECOMP       precomp;      /* precomputed information */
  185.  
  186.   struct obj_struct *nextobj, /* next obj in list */
  187.                     *child;   /* child for bounding boxes only */
  188.  
  189.   PATTERN_PTR   pattern,      /* pointer to pattern structure */
  190.                 remove;       /* remove section of object */
  191.  
  192. } OBJ_STRUCT, *OBJ_PTR;
  193.  
  194.  
  195. /**********************************************************
  196.  
  197.                    Plane Bbox structure
  198.  
  199.  **********************************************************/
  200.  
  201. typedef struct _PlaneBox {
  202.   int      min_x, min_y,
  203.            max_x, max_y;
  204.  
  205.   OBJ_PTR  object;
  206.  
  207.   struct _PlaneBox *next;
  208. } PLANE_BBOX, *PLANE_BBOX_PTR;
  209.  
  210.  
  211. /**********************************************************
  212.  
  213.                        WORLD STRUCTURE
  214.  
  215.  **********************************************************/
  216.  
  217. typedef struct world {
  218.   OBJ_PTR   stack,            /* here are the objects */
  219.             observer,         /* the observer */
  220.             sky,              /* sky */
  221.             lamps,            /* a lamp list */
  222.             instances;        /* instance list */
  223.  
  224.   int       objcount,         /* # objects and lamps */
  225.             lampcount,
  226.             first_scan,       /* first, last scan lines */
  227.             last_scan;
  228.  
  229.   long      ray_intersects,   /* statistics */
  230.             primary_traced,
  231.             to_lamp,
  232.             refl_trans,
  233.             bbox_intersects,
  234.             intersect_tests,
  235.             pixels_hit,
  236.             pattern_matches;
  237.  
  238.   VECTOR    obsright,         /* obs up dir */
  239.             obsup;
  240.  
  241.   SVECTOR   skycolor_horiz,   /* skycolors */
  242.             skycolor_zenith;
  243.  
  244.   PATTERN_PTR patlist;        /* the pattern stack */
  245.  
  246.   float     flength,          /* focal length */
  247.             globindex;        /* global index of refraction */
  248.  
  249.   char      *outfile;         /* output file name */
  250.   FILE      *filept;          /* output file pointer */
  251. } WORLD;
  252.  
  253.  
  254. /**********************************************************
  255.  
  256.                   FUNCTIONS FOR OBJECT TYPES
  257.  
  258.  **********************************************************/
  259.  
  260. typedef struct obj_data {
  261.   int (*ColTest)();           /* collision test function ptr */
  262.   int (*FindNorm)();          /* normal finding function ptr */
  263.   int (*FindBbox)();          /* object bound function ptr   */
  264.   int (*RelPos)();            /* object relative position    */
  265.   int (*PreComp)();           /* info pre-computing routine  */
  266.   int (*Offset)();            /* offset object by dx, dy, dz */
  267.   int (*Resize)();            /* resize object by a multiple */
  268. } OBJ_DATA;
  269.  
  270.  
  271. /**********************************************************
  272.  
  273.                       MATH DEFINES
  274.  
  275.  **********************************************************/
  276.  
  277. #define sqr(x) ((x)*(x))
  278. #define DotProd(v1,v2) (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z)
  279. #define MIN(x,y) ((x)<(y) ? (x) : (y))
  280. #define MAX(x,y) ((x)>(y) ? (x) : (y))
  281. #define IABS(x)  ((x)>0   ? (x) : (-(x)))
  282.  
  283.  
  284. /**********************************************************
  285.  
  286.                       Default structure
  287.  
  288.  **********************************************************/
  289.  
  290. typedef struct def_struct {
  291.  
  292.   CINFO cinfo;             /* default colorinfo */
  293.  
  294.   short shadow,            /* shadows ? */
  295.         vlamp,             /* lamps visible (not yet implimented) */
  296.